from __future__ import absolute_import, division

from gui.panda.base import *


class ValueField(PNMImage):
    def __init__(self, map, filter):
        assert map is not None
        
        # Map dimensions need to be powers of 2
        assert math.log(map.width,  2) % 1 == 0
        assert math.log(map.height, 2) % 1 == 0
        
        self._map = map
        
        super(ValueField, self).__init__(self.width, self.height)
        
        self.fill(0, 0, 0)
        
        for tile in self.map:
            self.setXel(tile.x, tile.y, filter(tile))
    
    @property
    def map(self):
        return self._map
    
    @property
    def width(self):
        return self.map.width
    
    @property
    def height(self):
        return self.map.height
    
    @property
    def texture(self):
        texture = Texture()
        texture.load(self)
        
        return texture
